/**
 * @param {number} n
 * @returns {boolean}
 */
function isPrime(n) {
  for (let i = 2; i < n; i++) {
    if (n % i === 0) return false;
  }
  return true;
}
/**
 * @param {function} onPrime
 * @param {number} startAt
 * @param {number} count
 * @returns {void}
 */
function computePrimes(onPrime, startAt = 1, count = 10) {
  let currNum;
  // eslint-disable-next-line no-constant-condition
  for (currNum = startAt; true; currNum++) {
    if (isPrime(currNum)) {
      onPrime(currNum);
      count--;
    }
    if (count === 0) {
      console.timeEnd("computePrimesNaive");
      break;
    }
  }
}

console.time("computePrimesNaive");
computePrimes(
  /**
   * @param {number} prime
   */
  (prime) => {
    console.log(prime);
  },
);
